let todoId=0
export default {
  namespace: 'todos',
  state: {content:[],filter:''},
  reducers: {
    add(state, action) {
      let id = todoId++
      return {
        content: [...state.content, {
          text: action.text,
          completed: false,
          id: id
        }],
      }
    },
    toggle(state, action) {
      return {
        content: state.content.map(todo => {
          if (todo.id == action.id) {
            todo.completed = !todo.completed
            return todo
          } else {
            return todo
          }
        }),
      }
    },
    filter(state, action) {
      return Object.assign({}, state, {filter: action.filter})
    }
  },
  effects: {},
  subscriptions: {},
};
